package com.example.demo.lambda;

import java.util.ArrayList;
import java.util.List;
import java.util.function.Function;

/**
 * @Author xiao
 * @Date 2025/4/28 下午 10:21
 * @ClassName: Function
 * @Desc:
 */
public class FunctionInterface {
    public static void main(String[] args) {
        List<Integer> lists = List.of(1,2,3,4,5);
        List<String> map = map(lists, String::valueOf);
        System.out.println(map);

    }

    static List<String> map(List<Integer> list, Function<Integer,String> fn) {
        List<String> result = new ArrayList<>();
        for (Integer number : list) {
            //转换：将数字转为字符串，但以后可能改变转换规则
            //result.add(String.valueOf(number));
            result.add(fn.apply(number));
        }
        return result;
    }


}
